package com.imchenio.springscheduleexample.instance02;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;

//@Component
@Slf4j
public class ConfigurerSchedule implements SchedulingConfigurer {

    private String cron = "0/5 * * * * ?";

    public String getCron() {
        return this.cron;
    }

    public void setCron(String cron) {
        this.cron = cron;
    }

    @Override
    public void configureTasks(ScheduledTaskRegistrar registrar) {
        registrar.addTriggerTask(() -> {
            log.info("cronTask");
        }, triggerContext -> {
            final String corn = cron;
            return new CronTrigger(corn).nextExecutionTime(triggerContext);
        });
    }


}
